<style>
.data-div {
	margin-top: 20px;
}
</style>
<template>
  	<div class="question">
    	<div class="content-div">
			<Row style="margin-top:10px">
				<Col span="14" class="table-form-input-select-col">
					<span class="alltitle" style="line-height:30px"><router-link to="项目列表"> 项目列表</router-link> > 预备员工专区 > <router-link to="activity">活动</router-link></span>
				</Col>
			</Row>
		</div>
		<div class="content-div data-div">
			<Table :columns="columns" :data="list" border stripe ref="table"></Table>
		</div>
  	</div>
</template>
<script>
export default {
    data() {
		return {
			qid: 0,
			columns: [
            {
                title: "序号",
                key: "id",
                width: 99,
            }, 
            {
                title: "姓名",
                key: "name",

            }, 
            {
                title: "获得积分",
                key: "integral",

            },
            {
                title: '是否参加',
                render: (h, params) => {
                    var attend = this.list[params.index].participate
                    var content = '待定'
                    if (attend == 2) {
                        content = '已参加'
                    }
                    else if (attend == 3) {
                        content = '未参加'
                    }
                    return h('span', {}, content)
                }
            },
            {
                title: "操作",
                key: "operate",
                width: 200,
                render: (h, params) => {
                    var attend = this.list[params.index].participate
                    if (attend == 1) {
                        return h("div", [ 
                            h(
                                "span", {
                                    style: {
                                        textDecoration: "underline",
                                        color: "#4b80fd",
                                        cursor: "pointer"
                                    },
                                    on: {
                                        click: () => {
                                            this.attendClick(params.index);
                                        }
                                    }
                                },
                                "参加活动"
                            ),
                            h(
                                "span", {
                                    style: {
                                        textDecoration: "underline",
                                        color: "#4b80fd",
                                        cursor: "pointer",
                                        'margin-left': "5px",
                                    },
                                    on: {
                                        click: () => {
                                            this.unattendClick(params.index);
                                        }
                                    }
                                },
                                "未参加活动"
                            )
                        ])
                    }
                }
            }],
			list: []
		}
	},
	created(){
          //获取传入的参数
          var params = this.$route.params;
          this.qid = params.qid;
          this.get()
     },
    methods: {
        get() {
            var self = this
            var poid = localStorage.pid;
            $.ajax({
                url: "https://evp.51job.com/51job/api/1.0/index.php/minirs/user_activity/getActicityUser",
                type: "POST",
                data: {
                    "project_id": poid,
                    "activity_id": this.qid
                },
                dataType: "json",
                success: function(data) {
                    console.log(data)
                    if (data.code == 1) {
                        self.list = data.data
                            // self.pageData.total = parseInt(data.datatotal)
                            // self.pageData.pageSize = 20
                            // self.pageData.current = currentPage
                        }
                        else {
                            self.$Message.error(data.msg);
                        }
                    }
                });
        },
    	attendClick(index) {
            var self = this
            self.$Modal.confirm({
                title: '确认参加？',
                content: '',
                onOk: () => {
                    console.log(self.list[index].id)
                    var poid = localStorage.pid;
                    $.ajax({
                        url: "https://evp.51job.com/51job/api/1.0/index.php/minirs/user_activity/getAffirmActicityUser",
                        type: "POST",
                        data: {
                            "project_id": poid,
                            "activity_id": this.qid,
                            "user_id": self.list[index].id,
                            "type": 2
                        },
                        dataType: "json",
                        success: function(data) {
                            console.log(data)
                            if (data.code == 1) {
                                self.$Message.success("操作成功！");
                                self.get()
                            }
                            else {
                                self.$Message.error(data.msg);
                            }
                        }
                    });
                },
                onCancel: () => {
                    this.$Message.info('取消参加');
                }
            });
        },
        unattendClick(index) {
            var self = this
            self.$Modal.confirm({
                title: '确认未参加？',
                content: '',
                onOk: () => {
                    console.log(self.list[index].id)
                    var poid = localStorage.pid;
                    $.ajax({
                        url: "https://evp.51job.com/51job/api/1.0/index.php/minirs/user_activity/getAffirmActicityUser",
                        type: "POST",
                        data: {
                            "project_id": poid,
                            "activity_id": this.qid,
                            "user_id": self.list[index].id,
                            "type": 3
                        },
                        dataType: "json",
                        success: function(data) {
                            console.log(data)
                            if (data.code == 1) {
                                self.$Message.success("操作成功！");
                                self.get()
                            }
                            else {
                                self.$Message.error(data.msg);
                            }
                        }
                    });
                },
                onCancel: () => {
                    this.$Message.info('取消未参加');
                }
            });
        }
    }
};
</script>
